home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: tjensen@ix.netcom.com (Ted Jensen)
- Newsgroups: comp.lang.c
- Subject: Re: What's so different about 2-D arrays???
- Date: Tue, 02 Jan 1996 18:28:49 GMT
- Organization: Netcom
- Message-ID: <4cbtg9$6o0@ixnews8.ix.netcom.com>
- References: <820451938.20697@fredblog.demon.co.uk>
- Reply-To: tjensen@ix.netcom.com
- NNTP-Posting-Host: pax-ca14-11.ix.netcom.com
- X-NETCOM-Date: Tue Jan 02 10:28:25 AM PST 1996
- X-Newsreader: Forte Free Agent 1.0.82
-
- mark@fredblog.demon.co.uk (Mark Winfield) wrote:
-
- >I have been teaching myself 'C' over the last month. Just before Xmas
- >I thought that I had it worked out and that all I had to do was
- >practice. I decided to write a program that would record chess games,
- >it would allow move branching as well. I decided upon this because it
- >should use everything I have learnt except DOS calls.
- >Now for the problem,
-
- >//My own chess recorder program
-
- >#include <stdio.h>
- >#include <ctype.h>
-
- >/*Prototypes*/
- >void setup(char pos[8][8]);
-
-
- >void main()
- >{
- >char pos[8][8];
-
- > setup(pos);
-
-
- > printf("\nWell Done!!");
- >}
-
- >void setup(char pos[8][8])
- >{
- >int x,y;
-
- > pos[1][8]=pos[8][8]='r';
- > pos[2][8]=pos[7][8]='n';
- > pos[3][8]=pos[6][8]='b';
-
- > pos[1][1]=pos[8][1]='R';
- > pos[2][1]=pos[7][1]='N';
- > pos[3][1]=pos[6][1]='B';
-
- > for(x=1;x<9;x++){
- > pos[x][7]='a';
- > pos[x][2]='A';
-
- > for(y=3;y<7;y++)
- > pos[x][y]=' ';
- > }
-
- > pos[4][8]='q';
- > pos[5][8]='k';
-
- > pos[4][1]='Q';
- > pos[5][1]='K';
- >}
-
- >This program does not work with a '.c' or '.cpp' extension. If I run
- >the program from dos I get well done and then something about NULL
- >pointers and the program hangs, so I have to reset. And if I run the
- >program from within the TURBO C++ enviroment the program hangs after
- >printing well done.
-
- >I have written a similar program since, as a test, which uses a 1-D
- >array with no problems. Can someone help me with this problem.
-
- Your basic problem here is that you are forgetting that when you
- dimension an array with size 8, the range of index values runs from
- zero to 7 instead of 1 to 8.
-
- You might want to grab a copy of a tutorial I wrote (ptrtut01.zip) for
- beginners on pointers and arrays which should clear up any other
- problems you may have here. It is available at either of the
- following sites:
-
- http://oak.oakland.edu:8080/SimTel/msdos/c/ptrtut01.zip
-
- ftp.coast.net/SimTel/msdos/c/ptrtut01.zip
-
- or any of SimTel mirror sites.
-
-
-
-
- Ted Jensen Author of PTRTUT01.ZIP
- Redwood City, CA A tutorial on C pointers and Arrays
- tjensen@ix.netcom.com Available via Simtel/msdos/c
-
-